package com.yjn.blog.service.impl;

import com.yjn.blog.dao.UserTextDao;
import com.yjn.blog.model.UserText;
import com.yjn.blog.model.http.BlogReq;
import com.yjn.blog.model.http.CursorPageReq;
import com.yjn.blog.model.http.CursorPageResp;
import com.yjn.blog.service.BlogService;
import com.yjn.blog.util.bean.BaseResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Classname: BlogServiceImpl
 * Package: com.yjn.blog.service.impl
 * Description:
 *
 * @Author 余集楠
 * @Create 2024/7/16 0016 22:06
 * @Version 1.8
 */
@Service
@Slf4j
public class BlogServiceImpl implements BlogService {
    @Autowired
    UserTextDao userTextDao;

    @Override
    public BaseResponse create(BlogReq req) {
        return BaseResponse.ok(userTextDao.insert(req));
    }

    @Override
    public CursorPageResp getList(int userId, CursorPageReq req) {
         UserText all= userTextDao.selectByUserId(userId);

        log.info("===[开始请求游标分页查询：请求每页数量{}，游标值为{}]===",req.getPageSize(),req.getCursor());

        if(req.getCursor()==null){

        }
        List<UserText> list  =userTextDao.listForCursorPage(all);
        CursorPageResp resp=new CursorPageResp();
        if(list.size()>0){
            resp.setList(list);
            resp.setCursor(list.get(list.size()-1).getUserId());
        }
        return resp;
    }

    @Override
    public UserText getPostId(int postId) {
        return userTextDao.selectByPrimaryKey(postId);
    }

    @Override
    public int update(UserText userText) {
        return userTextDao.updateByPrimaryKeySelective(userText);
    }

    @Override
    public int delete(int postId) {
        return userTextDao.deleteByPrimaryKey(postId);
    }


}
